Skip to content

fix(driver-sql): a boolean retyped from text stores 1 / 0 on SQLite, so a saved false no longer reads as true - #35511

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-35341-sqlite-retyped-boolean
Nov 19, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-35341-sqlite-retyped-boolean

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb
Fixes #35341

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:在 SQLite 上,把字段类型从「文本」改成「是/否」之后,存「否」的记录现在读出来就是「否」,列表、去重、分组和「= 否」筛选结果一致;以前存成怪写法的老记录会在下次启动时自动纠正。
  • 为什么做:这类字段过去每次保存「否」都被存成「0.0」,读出来却显示「是」,筛选和显示互相矛盾,用户看到的是/否值是错的。
  • 出错会怎样:只影响 SQLite 上改过类型的是/否字段;新建的是/否字段存储形式不变。若启动时纠正失败,只会记一条警告并在下次启动重试,不会阻止启动。
  • 要你做什么:无,席位落地。

席位核对

  • Where to look first: sql-driver-sqlite-serialisation.ts (the new sqliteBooleanBinding and its use at the end of formatInput), then the comparand branch at the top of coerceFilterValue in sql-driver-filter-helpers.ts, then the widened SQLITE_LEGACY_BOOLEAN_TEXT and the UPDATE in backfillCanonicalBooleans (sql-driver-schema-sync.ts).
  • Two-minute check: pnpm --filter @objectstack/driver-sql exec vitest run --maxWorkers=2 src/sql-driver-35341-retyped-boolean-text-column.test.ts answers 11/11 green; the CONTROL describe (a boolean column the driver created) shows the integer 1 / 0 storage unchanged.
  • Route: B (the card's Ask), no read-side backstop. Reason: binding the write and the comparand as the text '1' / '0' and extending the boot convergence to '1.0' / '0.0' makes find(), distinct() and = false agree on new and existing rows, so presentStoredBoolean needs no widening (AGENTS.md Prime Directive 12) and the stored form converges on one spelling, the direction of PR fix(driver-sql): boot converges legacy text booleans on SQLite to 1 / 0 #35076.

What changes

On SQLite, a text field retyped to boolean keeps its TEXT column. knex's better-sqlite3 client binds a JS boolean as Number(b), better-sqlite3 binds a JS number as a REAL, and TEXT affinity keeps the REAL as the text '0.0' / '1.0', which presentStoredBoolean read as true both.

  • Write. formatInput (SQLite only) binds a declared scalar boolean (booleanFields) that holds a JS boolean as the text '1' / '0' (sqliteBooleanBinding). NUMERIC affinity (a column the driver created) folds it into the INTEGER 1 / 0, unchanged from before; TEXT affinity keeps '1' / '0', the spelling the boot convergence writes and the presenter reads. Every write door runs through formatInput: create, update, upsert, bulkCreate, bulkUpdate, updateMany.
  • Comparand. coerceFilterValue binds a boolean comparand on the same fields the same way, so = false / = true / $in / $ne select the rows the row read presents as that boolean.
  • Existing rows. SQLITE_LEGACY_BOOLEAN_TEXT (the backfill's count, sample, UPDATE and the os migrate plan preview all read it) now also selects '1.0' / '0.0', and the UPDATE maps them to 1 / 0. They were counted as withheld and warned about before.
  • A BigInt would bind an INTEGER too; it is not used because knex's query-text formatter throws on one (measured: str.replace is not a function).

Tests

New pin: sql-driver-35341-retyped-boolean-text-column.test.ts, 11/11 green

Three describes: the retyped TEXT column written through all six write doors (storage is the text 1 / 0; find(), distinct(), = false, = true, $ne, $in agree); a retyped column holding '0.0' / '1.0' / '0' across a boot (the plan counts 2 rows as normalize_boolean_storage, the boot rewrites them, withholds nothing, and the reads and filter agree); CONTROL, a boolean column the driver created (INTEGER 1 / 0, answers unchanged).

 Test Files  1 passed (1)
      Tests  11 passed (11)
Ablation, one arm per mechanism (scripts/ablation-replace.mjs; the test imports src, no dist on the path)
  • Arm 1, write bind removed (copy[field] = v;): anchor 1 to 0, blob 70f2a4d38a7c to aadb818335c5; 5 failed / 6 passed (storage, find, distinct, filters red; CONTROL green). Restored: blob == HEAD, git diff HEAD empty.
  • Arm 2, comparand branch removed (return value;): blob 21ac54f81c71 to 528a57d1a45e; 3 failed / 8 passed (= false / = true, $ne / $in, the existing-rows filter red). Restored.
  • Arm 3, convergence predicate back to ('true', 'false'): blob 66b443f687f8 to 3886962a9261; 3 failed / 8 passed (plan count, boot rewrite, existing-rows agreement red). Restored.
driver-sql package suite and typecheck
  • pnpm --filter @objectstack/driver-sql test (lock VERDICT command-exit 0, tree 5d191fa; the later head af25ec3 adds only the changeset): Test Files 265 passed, 13 skipped (278); Tests 4408 passed, 257 skipped (4665).
  • pnpm --filter @objectstack/driver-sql typecheck: exit 0 (tsconfig includes src/**/*, so the new test is compiled).

Acceptance notes

  • The data door was measured, before and after (todo example on a better-sqlite3 file database, a field booted as text then retyped to boolean; the example edit was a scratch edit, reverted, not in this diff). See Verification.
  • driver-sqlite-wasm and driver-turso inherit isSqlite and so take the same bind. sql.js already bound an integer-valued number as INTEGER, so a TEXT column there stored '0' before this change and stores '0' after; this was reasoned from sql.js's binder, not measured here.
  • A number 0 / 1 (not a JS boolean) handed straight to the driver is not rebound; the engine's boolean arm hands the driver JS booleans.

Verification

A0, the REST data door, origin/main 6f36818 vs this branch

Before (origin/main): after the retype boot, pragma_table_info reads probe_flag TEXT. POST /api/v1/data/todo_task with probe_flag: false answers 201 with "probe_flag":true; the cell is the text '0.0' (and '1.0' for true). The list reads both rows as true; the probe_flag = false filter returns the false row, presented as true.

After (driver-sql rebuilt at af25ec3, same database file): the boot rewrote the two rows to '0' / '1'. POST with false answers "probe_flag":false and stores '0'. The list reads [door_false,false],[door_true,true],[post_false,false],[post_true,true]; the = false filter returns exactly door_false and post_false, both false.

A1 to A3, measured on origin/main 6f36818 at the driver
  • A1: knex 3.3.0 client-better-sqlite3 _formatBindings maps a boolean to Number(b); better-sqlite3 13.0.3 binds it as REAL. On the retyped TEXT column, create, update, bulkCreate and updateMany all stored '0.0' / '1.0'; on an INTEGER-form column, 0 / 1.
  • A2: backfillCanonicalBooleans writes the integer 1 / 0, which a TEXT column stores as the text '1' / '0'. '0.0' / '1.0' were not in its population: a reboot logged left 7 row(s) of ... unconverted and changed nothing.
  • A3: presentStoredBoolean reads 'false' / '0' as false, 'true' / '1' as true, anything else as Boolean(value), so '0.0' reads true. The = false comparand bound as REAL compared as '0.0' on the TEXT column: it matched the '0.0' rows and missed the '0' row the convergence left.
Local gates (derived with dispatch-gates.mjs --commands, run on head af25ec3)

68 families derived for the 5 changed paths; 66 exit 0, 2 NOT MEASURED (exit 3, PREREQUISITE NOT MET): pnpm check:dual-build-cjs-loads (reads every package's dist; no whole-repo build here) and pnpm check:type-check-debt (its re-measure build never got a turn on the shared verify lock). Both run in CI's Lint & Repo Gates. dispatch-gates.mjs --ran with the exit codes recorded: ✓ 68 derived famil(ies) accounted for — 66 run, 2 NOT-MEASURED. overlap-check.mjs --branch=HEAD: VERDICT clean exit 0.


Generated by Claude Code

…and the boot converges 1.0 / 0.0

A text field retyped to boolean keeps its TEXT column on SQLite. knex binds a
JS boolean as a number, better-sqlite3 binds a number as REAL, and TEXT
affinity kept it as the text '1.0' / '0.0', which the row read presented as
true both. The write and the filter comparand of a declared scalar boolean now
bind the text '1' / '0' (NUMERIC affinity folds it to the integer 1 / 0; TEXT
keeps the spelling the boot convergence writes), and the convergence rewrites
existing '1.0' / '0.0' rows.

Claude-Session: https://claude.ai/code/session_01Utp6Ca1jJvsA1dHsPwMiQb
Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/driver-sql, touching 24 documentable anchor(s).

1 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/protocol/objectql/query-syntax.mdx (via coerceFilterValue (symbol, a method of class FilterHelpersFacet), coerceFilterValue (literal, a string literal in coerceFilterValue), storageDatetimeValue (literal, a string literal in coerceFilterValue; a string literal in formatInput))
What this run could not see
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 15 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 578d3b1d66c93bb5b9e1d113bf0d73501274aa3c → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 9ba9c48179657f76d136edbf6eeb9952c9e21e18 — the merge of head 52e9b07a63ac07dbce1007e898292056503320ab into base 578d3b1d66c93bb5b9e1d113bf0d73501274aa3c, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 9ba9c48179657f76d136edbf6eeb9952c9e21e18 && git checkout 9ba9c48179657f76d136edbf6eeb9952c9e21e18
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 578d3b1d66c93bb5b9e1d113bf0d73501274aa3c 52e9b07a63ac07dbce1007e898292056503320ab && git checkout -B drift-repro 578d3b1d66c93bb5b9e1d113bf0d73501274aa3c && git merge --no-ff 52e9b07a63ac07dbce1007e898292056503320ab

node scripts/docs-audit/affected-docs.mjs --json 578d3b1d66c93bb5b9e1d113bf0d73501274aa3c

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 578d3b1d66c93bb5b9e1d113bf0d73501274aa3c → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CXsZsKmgG1EcKp5bY4

维护者速读

  • 用户能看到什么变化:在 SQLite 上,把一个文本字段改成"是/否"字段后,保存"否"现在会正确显示为"否",按"否"筛选也只出现真正为"否"的记录。
  • 为什么做:以前这种字段存进去的是"0.0",读出来全都变成"是",筛选和统计也跟着错。
  • 出错会怎样:只影响 SQLite;原本就是"是/否"类型建出的字段,存储方式不变。已存错的旧数据会在下次启动时自动纠正,不用手动处理。
  • 要你做什么:无。区域合并主线后自行落地。

席位核对

L1-a: ACCEPT · head af25ec33ef9b5f4adac57664ab038caf738f398b · Fixes #35341 · 2026-11-19T13:21Z

Readings: check-governed-merges --pr 35511 not governed; merge-tree against main clean; CI 37 success / 16 skipped / 0 failed. K=20: merge main and get a green re-run before queueing. The PR is a draft, so mark it ready.

Code (driver-sql only, 5 files, +271/−13).

  • sqliteBooleanBinding binds '1' / '0'. It is applied in formatInput, after the isSqlite return, to each declared scalar boolean field (booleanFields[object]) holding a JS boolean, copy-on-write. It is applied in coerceFilterValue to a boolean comparand on a declared boolean column; arrays recurse, so $in is covered.
  • The conversion is done by the storage engine's column affinity, not by the client. NUMERIC affinity folds '1' to INTEGER 1, so driver-created columns keep their stored form. TEXT affinity keeps '1', the spelling presentStoredBoolean reads and the backfill writes. In a comparison, SQLite applies the column's affinity to the bound text, so = false meets the same form on both kinds of column.
  • SQLITE_LEGACY_BOOLEAN_TEXT adds '1.0', '0.0'. The backfill UPDATE becomes case when ?? in ('true','1.0') then 1 else 0 end, gated by the same predicate. That keeps five ?? for five bindings, so only the four spellings are touched, and a converged column stays a no-op. The plan preview reads the same predicate.

Pins. driver-35341-…test.ts, 11 cases plus a CONTROL INTEGER column:

  • six write paths (create, update, bulkCreate, updateMany, upsert, bulkUpdate);
  • the = false / = true / in comparands;
  • boot convergence of '1.0'/'0.0'.

Three ablations (the write bind, the comparand, and the convergence predicate) each went red, with the CONTROL green in all three. A0 at the REST door shows main storing '0.0' and listing it as true, and the fixed head converging those rows.

The judgment asked: the sqlite-wasm / turso reading is accepted without a measurement. The fix binds text, and every SQLite client can bind text. What turns '1' into INTEGER 1, or keeps it as '1', is the column affinity applied by the SQLite engine on store and compare, the same engine under sql.js and libsql. So the stored form does not depend on the client's number binding, which was the defect's source. A measurement on those clients is welcome on a later dogfood pass, but is not a landing condition.

Declaration: agreed. Clause-②: no / Metadata-protocol: none / @objectstack/driver-sql patch. No call that answered now refuses. Driver-created INTEGER columns store what they stored. A retyped TEXT column moves from a wrong '0.0' to the read-consistent '0', and the boot converges it.

Routing. Not governed, no contract face: data-1 merges main (K=20), then lands on green. A merge-only push needs no fresh L1.

K=20 against main per L1-a; merge-only.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6Ca1jJvsA1dHsPwMiQb
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb

Landing · area data-1 · 2026-11-19T13:53Z

reading value
L1-a ACCEPT 7010360361 at af25ec33ef (sqlite-wasm / turso reading accepted, since column affinity decides the stored form)
Head 52e9b07a63: a merge of origin/main into af25ec33ef (K was 20). It is merge-only, so no fresh L1 is owed. CI is green on this head
check-governed-merges --pr 35511 NOT governed; driver-sql only; no contract face
Declaration Clause-②: no / Metadata-protocol: none / @objectstack/driver-sql patch (agreed by L1-a)

State: draft → ready + auto-merge (merge queue). #35341 closes on merge via Fixes.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 19, 2026 13:54
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit c0484c8 Nov 19, 2026
54 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-35341-sqlite-retyped-boolean branch November 19, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants